package com.scau.controller;

import com.scau.entity.*;
import com.scau.fegin.OrderFegin;
import com.scau.fegin.UserFegin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderFegin orderFegin;

    @PostMapping(value = "/save",produces = "application/json;charset=UTF-8;")
    @ResponseBody
    public void save(@RequestBody PayForm payForm){

        System.out.println(payForm);
        orderFegin.save(payForm);
    }

    @GetMapping("/findAll")
    @ResponseBody
    public OrderVO findAll(@RequestParam("page") int page, @RequestParam("limit") int limit){
        System.out.println(page + " " +limit);
        return orderFegin.findAll((page-1)*limit,limit);
    }

    @GetMapping("/updateState/{orderId}/{state}")
    @ResponseBody
    public String updateState(@PathVariable("orderId") int orderId, @PathVariable("state") int state){
        orderFegin.updateState(orderId,state);
        return "sussess";
    }

    @GetMapping("/findByUId/{uid}")
    @ResponseBody
    public OrderVO findByUId(@RequestParam("page") int page, @RequestParam("limit") int limit,@PathVariable("uid") int uid){
        System.out.println(page + " "+limit);
        OrderVO byUId = orderFegin.findByUId((page-1)*limit,limit,uid);
        System.out.println(byUId);
        return byUId;
    }

    @GetMapping("/findByOrderId/{orderId}")
    @ResponseBody
    public OrderDetailVO findAllByOrderId(@RequestParam("page") int page, @RequestParam("limit") int limit,@PathVariable("orderId") int orderId){
        return orderFegin.findAllByOrderId((page-1)*limit,limit,orderId);
    }
}
